# Build release for PBS Software

RELDATE = $(shell eval date +%Y-%m-%d)
SERIALNO = 02
VERSION = $(RELDATE)-$(SERIALNO)
RELDIR = releases/pbs-sw-$(VERSION)
RELZIP = pbs-sw-$(VERSION).zip

DIRS = $(RELDIR)/xsl $(RELDIR)/doc $(RELDIR)/doc/images $(RELDIR)/xpl

DOCS = $(RELDIR)/readme.html $(RELDIR)/doc/reference.html

XSLT2HTML = build/xsl/xslt2html.xsl
FOSSHEET = build/xsl/fo.xsl
FOPORTRAITSSHEET = build/xsl/fo-portrait.xsl
HTMLSSHEET = build/xsl/html.xsl
REVHISTORYSSHEET = build/xsl/revhistory.xsl

SAXON = saxon
XSLTPROC = xsltproc
XMLLINT = xmllint
DOT = dot
FOP = fop
RM = rm
MV = mv
CP = cp

all:	release

release:	stylesheets pipeline doco
	(cd releases; zip -r $(RELZIP) pbs-sw-$(VERSION))
	-rm -rf releases/pbs-sw-current releases/pbs-sw-current.zip
	mkdir releases/pbs-sw-current
	cp -r releases/pbs-sw-$(VERSION)/* releases/pbs-sw-current
	(cd releases; zip -r pbs-sw-current.zip pbs-sw-current)

dirs:	$(DIRS)

stylesheets:	$(RELDIR)/xsl
	$(CP) xsl/* $(RELDIR)/xsl

doco:	$(RELDIR)/doc $(DOCS) install-images $(XSLT2HTML) Makefile
	@list='xsl/*.xsl'; for i in $$list; do \
	    echo "Extracting doco for `basename $$i`" ; \
	    $(XSLTPROC) -o $(RELDIR)/doc/`basename $$i .xsl`.html $(XSLT2HTML) $$i ; \
	done;
	@echo "Stylesheet doco done"

install-images:	$(RELDIR)/doc/images
	$(CP) doc/images/* $(RELDIR)/doc/images

$(RELDIR)/readme.html:	doc/readme.xml $(HTMLSSHEET) Makefile
	$(XSLTPROC) -o $@ --stringparam version $(VERSION) $(HTMLSSHEET) $<

$(RELDIR)/doc/reference.html:	doc/reference.xml $(HTMLSSHEET) Makefile
	$(XSLTPROC) -o $@ --stringparam version $(VERSION) $(HTMLSSHEET) $<

pipeline:	$(RELDIR)/xpl
	cp -r xpl/* $<

$(DIRS):
	mkdir -p $@

clean:
	rm -rf samples/schedule-pbs.xml
	rm -rf releases/*
	rm -rf website/*

# Implicit rules

%.fo:	%.xml $(FOSSHEET)
	$(XSLTPROC) -o $@ $(FOSSHEET) $<

%.html:	../xml/%.xml $(HTMLSSHEET)
	$(XSLTPROC) -o $@ $(HTMLSSHEET) $<

%.pdf:	%.fo
	cd `dirname $<`; $(FOP) `basename $<` `basename $@`

%.png:	%.dot
	$(DOT) -Gratio=0.5 -Tpng -o$@ $<

%.svg:	%.dot
	$(DOT) -Gratio=0.5 -Tsvg -o$@ $<
